package com.persondemo.videoappliction.ui.adapter;

import android.content.Context;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lzy.ninegrid.ImageInfo;
import com.lzy.ninegrid.NineGridView;
import com.lzy.ninegrid.preview.NineGridViewClickAdapter;
import com.persondemo.videoappliction.R;
import com.persondemo.videoappliction.bean.ZiXunBean;
import com.persondemo.videoappliction.utils.ImageLoaderUtil;

import java.util.ArrayList;
import java.util.List;

public class ZiXunAdapter extends BaseMultiItemQuickAdapter<ZiXunBean.DataBean, BaseViewHolder> {
    private Context mContext;

    public ZiXunAdapter(List<ZiXunBean.DataBean> data, Context mContext) {
        super(data);
        this.mContext = mContext;
        addItemType(ZiXunBean.DataBean.types_01, R.layout.item_zixun_01);
        addItemType(ZiXunBean.DataBean.types_02, R.layout.item_zixun_02);
        addItemType(ZiXunBean.DataBean.types_03, R.layout.item_zixun_03);
    }

    @Override
    protected void convert(BaseViewHolder helper, ZiXunBean.DataBean item) {
        switch (helper.getItemViewType()) {
            case ZiXunBean.DataBean.types_01:
                helper.setText(R.id.item_zixun_01_title, item.getTitle());
                break;
            case ZiXunBean.DataBean.types_02:
                helper.setText(R.id.item_zixun_02_title,item.getTitle());
                ImageLoaderUtil.LoadImage(mContext,item.getImgs().get(0),helper.getView(R.id.item_zixun_02_img));
                break;
            case ZiXunBean.DataBean.types_03:
                helper.setText(R.id.item_zixun_03_title,item.getTitle());
                List<ImageInfo> imageInfo=new ArrayList<>();
                if (item.getImgs() != null) {
                    for (String imageDetail : item.getImgs()) {
                        ImageInfo info = new ImageInfo();
                        info.setThumbnailUrl(imageDetail);
                        info.setBigImageUrl(imageDetail);
                        imageInfo.add(info);
                    }
                }
                NineGridView nineGridView=helper.getView(R.id.item_zixun_03_nineGrid);
                nineGridView.setAdapter(new NineGridViewClickAdapter(mContext, imageInfo));
                break;
        }
    }
}
